<script type="text/javascript" charset="utf-8">

	/* Global var for counter */
	var positionCount = 0;
	
	$(function(){
	    	$("#mytag label").each(function(i){
			  	if(jQuery.trim($(this).html()) == "Candidates:"){
			  		var parentHeight = $(this).parent("div").height();
			  		$(this).height(parentHeight)
				 }
	    	});

	    	$("#vote").click(function(){
	    		var rs = inputCheck();
		    	if(rs =="OK"){
			    	$("#electCreatFrom").submit();
			    	
		    	}else{
			    	
		    	}
				
			});
	});

	
	function inputCheck(){
		var result = 'OK';
		
		var blockCount = $("#maxIndex").val();
		
		for (var i=0; i< blockCount; i++){
			//div id 取得
			var divId = "#checkdiv"+i;
			divId += " input";
			//最大选择数取得
			var selectMax = "#selectMax"+i;
			selectMax = $(selectMax).val();
			
			var checkedCount = 0;
			
			$(divId).each(function(i){
				
			  	if($(this).is(':checked')){ checkedCount ++;}
			});

			var msgDiv = "#msgDiv"+i;
			$(msgDiv).val('');
			if (checkedCount > selectMax){
				$(msgDiv).val('At most You Can check it for '+selectMax);
				result = 'NG';
			}
		}

		return result;
	}
</script>


<!-- /.section, /#navigation -->
<div id="main-wrapper">
  <div id="main" class="clearfix with-navigation">
    <div id="content" class="column">
		 <div class="breadcrumb" ><h3>Vote </h3></div>
      <div class="section">
        <div id="content-area">
          <form action="<!--{$smarty.const.HTTP_URL}-->elect/elect_vote.php" method="post" id="electCreatFrom" >
          <input type="hidden" name="mode" id="mode" value="vote" />
          <input type="hidden" name="<!--{$smarty.const.TRANSACTION_ID_NAME}-->" value="<!--{$transactionid}-->" />
              
              <div class="form-item" id="edit-mail-wrapper">
                <label for="edit-mail">Election Tilte:</label>
                <input maxlength="64" name="election" id="election" size="60" value="<!--{$electionTilte|escape}-->" class="form-text required" type="text" style = "border-style:none;background-color: #FFFFFF" readonly="readonly">
              	<input type="hidden" name="electionId"  value="<!--{$electionId|escape}-->" />
              </div>
              
              <div class="form-item" id="edit-mail-wrapper">
                <label for="edit-mail">Time Zone: 
                </label>
                <input maxlength="10" name="startDate"  value="<!--{$startDate|escape}-->" class="form-text required" type="text" style = "border-style:none;background-color: #FFFFFF;width:90px" readonly="readonly">
              	-
              	<input maxlength="10" name="endDate"   value="<!--{$endDate|escape}-->" class="form-text required" type="text" style = "border-style:none;background-color: #FFFFFF;width:90px" readonly="readonly">
	              <input name="bk" id="back" value="Go back" class="form-submit" type="button" onclick='history.back();' style=" float:right; width:100px; ">
	              <!--{if $smarty.session.authority == $smarty.const.AUTHORITY_ELECT_ADMIN }-->
		              <input name="op" id="vote" value="Vote" class="form-submit" type="button" style=" float:right; width:100px; ">
		          <!--{else}-->
		              <input name="op" id="vote" value="Vote" class="form-submit" type="button" style=" float:right; width:100px; "disabled>
		          <!--{/if}-->
              </div>
<div id="mytag">   
<!--{section name=counter loop=$positionInfoArr}-->	
						
            <div class="form-item" id="edit-mail-wrapper" style="margin-top:20px">
                <label for="edit-mail"><font size="2">Position Name:</font> 
                </label>
                <input maxlength="50" name="positionName[<!--{$smarty.section.counter.index}-->]"  value="<!--{$positionInfoArr[counter].position_name|escape}-->" class="form-text required" type="text" style = "border-style:none;background-color: #FFFFFF;" readonly="readonly">
            	<input id="msgDiv<!--{$smarty.section.counter.index}-->" value=""  type="text" style = "border-style:none;background-color: #FFFFFF;color:red;width:200px" readonly="readonly">
            	<input type="hidden" name="positionId[<!--{$smarty.section.counter.index}-->]"  value="<!--{$positionInfoArr[counter].id|escape}-->" />
            </div>
            <hr>
			<fieldset class="group-select2" style="margin-top:-10px">
                <legend>select2 </legend>
                	<div class="form-item">
	                  <label>Candidates:</label>
	                  <div class="form-radios" >
	                  	<!--{section name=index loop=$candidateArr[counter]}-->	
	                    <div class="form-item" id="checkdiv<!--{$smarty.section.counter.index}-->">
	                      <label class="option" for="edit-field-mailmagazine-value-agree">
	                        <input name="candidateId[<!--{$smarty.section.counter.index}-->][]" value="<!--{$candidateArr[counter][index].id|escape}--> " class="form-radio" type="checkBox"><!--{$candidateArr[counter][index].candidature_name|escape}-->
	                      </label>
	                    </div>
	                    <!--{/section}-->
	                  </div>
	                </div>
             </fieldset>
               <div class="description">
               		At most You Can check it for 
               		<input id= "selectMax<!--{$smarty.section.counter.index}-->"type="hidden" name ="selectMax[counter]" value="<!--{$positionInfoArr[counter].number_limite|escape}-->"/>
               		<span class="form-required" title="This field is required."><!--{$positionInfoArr[counter].number_limite|escape}--> </span>
               </div>
  <!--{/section}-->
  				<input type="hidden" id ="maxIndex" value="<!--{$positionInfoArrSize}-->"/>
 </div>                  
           
               <hr> 
              
          </form>
        </div>
      </div>
    </div>
    <!-- /.section, /#content -->
  </div>
</div>
<!-- /#main, /#main-wrapper -->
